#!/usr/bin/python

# include the contrib config file
import build_contrib
import os
import shutil

# set pkg info
PKG_NAME="sqlite"
PKG_VERSION="autoconf-3071000"
PKG_ARCHIVE="tar.gz"

#
build_contrib.begin_build(PKG_NAME, PKG_VERSION)
build_contrib.do_extract(PKG_NAME, PKG_VERSION, PKG_ARCHIVE)
build_contrib.do_patch(PKG_NAME, PKG_VERSION)

# configure
if build_contrib.pushd("%s/%s-%s" % (build_contrib.BUILD_PREFIX, PKG_NAME, PKG_VERSION)) != 0: exit( 1 )
if build_contrib.TARGET_SYSTEM_NAME == "windows":
	pass
else:
	if os.system("./configure --prefix=%s" % build_contrib.INSTALL_PREFIX) != 0 : build_contrib.popd_and_exit()
build_contrib.popd()


# build & install
if build_contrib.pushd("%s/%s-%s" % (build_contrib.BUILD_PREFIX, PKG_NAME, PKG_VERSION)) != 0: exit( 1 )
if build_contrib.TARGET_SYSTEM_NAME == "windows":
	if os.system("devenv sqlite3.sln /Rebuild \"%s|Win32\"" % build_contrib.CMAKE_BUILD_TYPE) != 0: build_contrib.popd_and_exit()
	try:
		build_contrib.recursive_copy("./sqlite3.h", "%s/include/sqlite3.h" % build_contrib.INSTALL_PREFIX)
		build_contrib.recursive_copy("./%s/sqlite3.lib" % build_contrib.CMAKE_BUILD_TYPE, "%s/lib/sqlite3.lib" % build_contrib.INSTALL_PREFIX)
	except:
		build_contrib.popd_and_exit()
else:
	if os.system("make") != 0: build_contrib.popd_and_exit()
	if os.system("make install") != 0: build_contrib.popd_and_exit()
build_contrib.popd()

# end
build_contrib.end_build(PKG_NAME, PKG_VERSION)
